<script setup lang="ts">
import { PropType } from 'vue'
import { ListItem, ListOptions, ActionOptions } from './types'
import { toLine } from '@/utils/index'

const props = defineProps({
  // 列表的内容
  list: {
    type: Array as PropType<ListOptions[]>,
    required: true
  },
  actions: {
    type: Array as PropType<ActionOptions[]>,
    default: () => []
  }
})

const emits = defineEmits(['clickListItem', 'clickAction'])

// 点击列表项
const onClickListItem = (item: ListItem, index: number) => {
  emits('clickListItem', { item, index })
}
// 点击操作
const onClickAction = (action: ActionOptions, index: number) => {
  emits('clickAction', { action, index })
}
</script>

<template>
  <div class="list-tabs-item">
    <el-tabs>
      <el-tab-pane v-for="(item, index) in list" :key="index" :label="item.title">
        <el-scrollbar max-height="240px">
          <div
            class="container"
            @click="onClickListItem(contentItem, contentIndex)"
            v-for="(contentItem, contentIndex) in item.content"
            :key="contentIndex"
          >
            <div class="avatar">
              <el-avatar :src="contentItem.avatar" />
            </div>
            <div class="content">
              <div v-if="contentItem.title" class="title">
                <div>{{ contentItem.title }}</div>
                <el-tag v-if="contentItem.tag" size="mini" :type="contentItem.tagType">{{ contentItem.tag }}</el-tag>
              </div>
              <div v-if="contentItem.desc">{{ contentItem.desc }}</div>
              <div class="time">{{ contentItem.time }}</div>
            </div>
          </div>
        </el-scrollbar>
        <ul class="actions">
          <li class="a-item" v-for="(action, i) in actions" :key="i" @click="onClickAction(action, i)">
            <div class="a-icon" v-if="action.icon">
              <component :is="`el-icon${toLine(action.icon)}`" />
            </div>
            <span class="a-text">{{ action.text }}</span>
          </li>
        </ul>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<style lang="scss" scoped>
.list-tabs-item {
  :deep(.el-tabs__nav) {
    width: 100%;
    display: flex;
  }
  :deep(.el-tabs__item) {
    flex: 1;
    text-align: center;
    padding: 0;
  }
  .container {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    &:hover {
      background-color: #e6f6ff;
    }
    .avatar {
      flex: 1;
    }
    .content {
      flex: 3;
      .title {
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
      .time {
        font-size: 12px;
        color: #999;
        margin-top: 4px;
      }
    }
  }
  .actions {
    height: 40px;
    display: flex;
    align-items: center;
    border-top: 1px solid #eee;
    .a-item {
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100%;
      cursor: pointer;
      transition: all 0.3s ease-in-out;
      &:hover {
        background: #efefef;
      }
      &:first-child {
        border-right: 1px solid #eee;
      }
      .a-icon {
        margin-right: 4px;
        position: relative;
        top: 2px;
      }
    }
  }
}
</style>
